using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System;


namespace FoundationLib.Ifc.Data 
{
	/// <summary>
	/// Represents a configuration for aggregate repositories
	/// </summary>
	public class RepositoryConfiguration 
	{
		/// <summary>
		/// Indicates whether this repository uses snapshotting
		/// </summary>
		private bool enableSnapshotting;
		/// <summary>
		/// The maximum number of events to store for an aggregate before a snapshot is
		/// taken
		/// </summary>
		private int snapshotEventThreshold;

		/// <summary>
		/// Creates a new configuration instance
		/// </summary>
		public RepositoryConfiguration()
		{
			this.enableSnapshotting = true;
			this.snapshotEventThreshold = 5;
		}

		/// <summary>
		/// Sets a value indicating whether snapshotting is enabled
		/// </summary>
		/// <returns>This instance</returns>
		/// <param name="value">True if shapshotting is to be enabled, false
		/// otherwise</param>
		public RepositoryConfiguration SetEnableSnapshotting(bool value)
		{
			this.enableSnapshotting = value;
			return this;
		}

		/// <summary>
		/// Gets a value indicating whether this repository uses snapshotting
		/// </summary>
		public bool EnableSnapshotting
		{
			get
			{
				return this.enableSnapshotting;
			}
		}

		/// <summary>
		/// Sets the maximum number of events before a snapshot is created
		/// </summary>
		/// <returns>This instance</returns>
		/// <param name="value">The maximum number of events</param>
		public RepositoryConfiguration SetSnapshotEventThreshold(int value)
		{
			if (value < 1)
				throw new ArgumentOutOfRangeException("value", "Value must be a positive integer greater than 0.");

			this.snapshotEventThreshold = value;
			return this;
		}

		/// <summary>
		/// Gets the maximum number of events to store for an aggregate before a snapshot
		/// is taken
		/// </summary>
		public int SnapshotEventThreshold
		{
			get
			{
				return this.snapshotEventThreshold;
			}
		}

	}

}